for (TargetType, TargetFunc, SourceConversion) in (
    (:Nanoseconds, :nanoseconds, (
       (:Microseconds, NANOSECONDS_PER_MICROSECOND),
       (:Milliseconds, NANOSECONDS_PER_MILLISECOND),
       (:Seconds, NANOSECONDS_PER_SECOND),
       (:Minutes, NANOSECONDS_PER_MINUTE),
       (:QuarterHours, NANOSECONDS_PER_QUARTERHOUR),
       (:Hours, NANOSECONDS_PER_HOUR),
       (:Days, NANOSECONDS_PER_DAY),
       (:Weeks, NANOSECONDS_PER_WEEK),
    ) ),
    (:Microseconds, :microseconds, (
	(:Nanoseconds, NANOSECONDS_PER_MICROSECOND),
	(:Milliseconds, MICROSECONDS_PER_MILLISECOND),
	(:Seconds, MICROSECONDS_PER_SECOND),
	(:Minutes, MICROSECONDS_PER_MINUTE),
	(:QuarterHours, MICROSECONDS_PER_QUARTERHOUR),
	(:Hours, MICROSECONDS_PER_HOUR),
	(:Days, MICROSECONDS_PER_DAY),
	(:Weeks, MICROSECONDS_PER_WEEK),
    ) ),
    (:Milliseconds, :milliseconds, (
       (:Nanoseconds, NANOSECONDS_PER_MILLISECOND),
       (:Microseconds, MICROSECONDS_PER_MILLISECOND),
       (:Seconds, MILLISECONDS_PER_SECOND),
       (:Minutes, MILLISECONDS_PER_MINUTE),
       (:QuarterHours, MILLISECONDS_PER_QUARTERHOUR),
       (:Hours, MILLISECONDS_PER_HOUR),
       (:Days, MILLISECONDS_PER_DAY),
       (:Weeks, MILLISECONDS_PER_WEEK),
    ) ),
    (:Seconds, :seconds, (
       (:Nanoseconds, NANOSECONDS_PER_SECOND),
       (:Microseconds, MICROSECONDS_PER_SECOND),
       (:Milliseconds, MILLISECONDS_PER_SECOND),
       (:Minutes, SECONDS_PER_MINUTE),
       (:QuarterHours, SECONDS_PER_QUARTERHOUR),
       (:Hours, SECONDS_PER_HOUR),
       (:Days, SECONDS_PER_DAY),
       (:Weeks, SECONDS_PER_WEEK),
    ) ),
    (:Minutes, :minutes, (
       (:Nanoseconds, NANOSECONDS_PER_MINUTE),
       (:Microseconds, MICROSECONDS_PER_MINUTE),
       (:Milliseconds, MILLISECONDS_PER_MINUTE),
       (:Seconds, SECONDS_PER_MINUTE),
       (:QuarterHours, MINUTES_PER_QUARTERHOUR),
       (:Hours, MINUTES_PER_HOUR),
       (:Days, MINUTES_PER_DAY),
       (:Weeks, MINUTES_PER_WEEK),
    ) ),
    (:QuarterHours, :quarterhours, (
       (:Nanoseconds, NANOSECONDS_PER_QUARTERHOUR),
       (:Microseconds, MICROSECONDS_PER_QUARTERHOUR),
       (:Milliseconds, MILLISECONDS_PER_QUARTERHOUR),
       (:Seconds, SECONDS_PER_QUARTERHOUR),
       (:Minutes, MINUTES_PER_QUARTERHOUR),
       (:Hours, QUARTERHOURS_PER_HOUR),
       (:Days, QUARTERHOURS_PER_DAY),
       (:Weeks, QUARTERHOURS_PER_WEEK),
    ) ),
    (:Hours, :hours, (
       (:Nanoseconds, NANOSECONDS_PER_HOUR),
       (:Microseconds, MICROSECONDS_PER_HOUR),
       (:Milliseconds, MILLISECONDS_PER_HOUR),
       (:Seconds, SECONDS_PER_HOUR),
       (:Minutes, MINUTES_PER_HOUR),
       (:QuarterHours, QUARTERHOURS_PER_HOUR),
       (:Days, HOURS_PER_DAY),
       (:Weeks, HOURS_PER_WEEK),
    ) ),
    (:Days, :days, (
       (:Nanoseconds, NANOSECONDS_PER_DAY),
       (:Microseconds, MICROSECONDS_PER_DAY),
       (:Milliseconds, MILLISECONDS_PER_DAY),
       (:Seconds, SECONDS_PER_DAY),
       (:Minutes, MINUTES_PER_DAY),
       (:QuarterHours, QUARTERHOURS_PER_DAY),
       (:Hours, HOURS_PER_DAY),
       (:Weeks, DAYS_PER_WEEK),
    ) ),
    (:Weeks, :weeks, (
       (:Nanoseconds, NANOSECONDS_PER_WEEK),
       (:Microseconds, MICROSECONDS_PER_WEEK),
       (:Milliseconds, MILLISECONDS_PER_WEEK),
       (:Seconds, SECONDS_PER_WEEK),
       (:Minutes, MINUTES_PER_WEEK),
       (:QuarterHours, QUARTERHOURS_PER_WEEK),
       (:Hours, HOURS_PER_WEEK),
       (:Days, DAYS_PER_WEEK),
    ) ),
    (:Months, :months, (
       (:Quarters, MONTHS_PER_QUARTER),
       (:Years, MONTHS_PER_YEAR),
       (:Decades, MONTHS_PER_DECADE),
       (:Centuries, MONTHS_PER_CENTURY),
    ) ),
    (:Quarters, :quarters, (
       (:Months, MONTHS_PER_QUARTER),
       (:Years, QUARTERS_PER_YEAR),
       (:Decades, QUARTERS_PER_DECADE),
       (:Centuries, QUARTERS_PER_CENTURY),
    ) ),
    (:Years, :years, (
       (:Months, MONTHS_PER_YEAR),
       (:Quarters, QUARTERS_PER_YEAR),
       (:Decades, YEARS_PER_DECADE),
       (:Centuries, YEARS_PER_CENTURY),
    ) ),
    (:Decades, :decades, (
       (:Months, MONTHS_PER_DECADE),
       (:Quarters, QUARTERS_PER_DECADE),
       (:Years, YEARS_PER_DECADE),
       (:Centuries, DECADES_PER_CENTURY),
    ) ),
    (:Centuries, :centuries, (
       (:Months, MONTHS_PER_CENTURY),
       (:Quarters, QUARTERS_PER_CENTURY),
       (:Years, YEARS_PER_CENTURY),
       (:Decades, DECADES_PER_CENTURY),
    ) ),
  )
  @eval $TargetFunc(x::$TargetType) = value(x)	
  for (SourceType, ConversionFactor) in SourceConversion
    @eval begin
        if islte($TargetType, $SourceType)
            Base.promote_rule(::Type{$TargetType}, ::Type{$SourceType}) = $TargetType
	    $TargetFunc(x::$SourceType) = value(x) * $ConversionFactor
	else				
    	    Base.promote_rule(::Type{$TargetType}, ::Type{$SourceType}) = $SourceType
	    $TargetFunc(x::$SourceType) = div(value(x), $ConversionFactor)
	end
        $TargetType(x::$SourceType) = $TargetType($TargetFunc(x))
	Base.convert(::Type{$TargetType}, x::$SourceType) = $TargetType(x)
    end
  end
end
